package part15;

/**
 * @author wcj
 * @Date 2021/5/29 17:09
 * @Version 1.0
 */
public class Part1512 {

    public static TwoTuple<String, Integer> f() {
        return Tuple.tuple("hi", 47);
    }

    public static TwoTuple f2() {
        return Tuple.tuple("hi", 47);
    }

    public static ThreeTuple<String, String, Integer> g() {
        return Tuple.tuple("hi", "bss", 47);
    }

    public static FourTuple<String, Integer, String, Double> h() {
        return Tuple.tuple("hi", 47, "bss", 3.14);
    }

    public static FiveTuple<String, Float, Double, Integer, Character> k() {
        return Tuple.tuple("hi", 3.14f, 3.24, 5, 'c');
    }

    public static void main(String[] args) {
        System.out.println(f());
        System.out.println(f2());
        System.out.println(g());
        System.out.println(h());
        System.out.println(k());
    }
}

/**
 * 元组和泛型结合能够很好的简化元组的使用，
 * 并且注意非参数化的类型无法转化为参数化的类型,Cat 无法转化为Cat<A,B?
 */
class Tuple {
    public static <A, B> TwoTuple<A, B> tuple(A a, B b) {
        return new TwoTuple<A, B>(a, b);
    }

    public static <A, B, C> ThreeTuple<A, B, C> tuple(A a, B b, C c) {
        return new ThreeTuple<>(a, b, c);
    }

    public static <A, B, C, D> FourTuple<A, B, C, D> tuple(A a, B b, C c, D d) {
        return new FourTuple<>(a, b, c, d);
    }

    public static <A, B, C, D, E> FiveTuple<A, B, C, D, E> tuple(A a, B b, C c, D d, E e) {
        return new FiveTuple<>(a, b, c, d, e);
    }
}
